<template>
  <div>
    <head-top></head-top>
    <visitor-pie
      :barData="barData"
      :userData="userData"
      :orderData="orderData"
      :adminData="adminData"
      :foodsData="foodsData"
    ></visitor-pie>
  </div>
</template>

<script>
import headTop from "../components/headTop";
import visitorPie from "@/components/countBar";
import {
  getResturantsCount,
  getUserCount,
  getAdminCount,
  getOrderCount,
  getFoodsCount,
} from "@/api/getData";
export default {
  data() {
    return {
      barData: {},
      userData: {},
      adminData: {},
      orderData: {},
      foodsData: {},
      //   restaurant_id: {},
    };
  },
  components: {
    headTop,
    visitorPie,
  },
  mounted() {
    this.restaurant_id = this.$route.query.restaurant_id;
    this.initData();
  },
  methods: {
    async initData() {
      //获取餐馆数量
      try {
        const res = await getResturantsCount();
        if (res.status === 1) {
          // console.log(res);
          this.barData = res;
        } else {
          throw new Error(res);
        }
      } catch (err) {
        console.log("获取餐馆总量失败", err);
      }
      //获取商品总量
      try {
        const countData = await getFoodsCount({
          restaurant_id: this.restaurant_id,
        });
        if (countData.status == 1) {
          this.foodsData = countData;
        } else {
          throw new Error("获取数据失败");
        }
      } catch (err) {
        console.log("获取数据失败", err);
      }
      //获取用户数量
      try {
        const res = await getUserCount();
        if (res.status === 1) {
          // console.log(res);
          this.userData = res;
        } else {
          throw new Error(res);
        }
      } catch (err) {
        console.log("获取餐馆总量失败", err);
      }
      //获取管理员数量
      try {
        const res = await adminCount();
        if (res.status === 1) {
          // console.log(res);
          this.adminData = res;
        } else {
          throw new Error(res);
        }
      } catch (err) {
        console.log("获取管理员总量失败", err);
      }
      //获取订单数量
      try {
        const res = await getOrderCount();
        if (res.status === 1) {
          // console.log(res);
          this.orderData = res;
        } else {
          throw new Error(res);
        }
      } catch (err) {
        console.log("获取订单总量失败", err);
      }
    },
  },
};
</script>

<style lang="less">
@import "../style/mixin";
</style>
